/*
* 自动获取焦点的指令
* */


import type{App,DirectiveBinding} from "vue"

function focusfunc(app:App,options:any){
    function aaa(el:HTMLElement,binding:DirectiveBinding){
        const dom:HTMLElement = el.querySelector("input") || el.querySelector("textarea") || el;
        dom.focus();
    }
    app.directive('focus', {
        beforeMount:function(){},
        mounted:function(el,binding:DirectiveBinding){
            const {arg,value} = binding
            console.log(binding,"看看默认是什么")
            if(value===undefined){
                aaa(el,binding)
            }else if(value){
                aaa(el,binding)
            }
        },
        unmounted:function(){},
    })
}

export default {
    install: focusfunc
}
